#include "ObjMap.h"
#include <iostream>

using std::cout;
using std::endl;

//map<string, Obj*> ObjMap::s_ObjPools;

ObjMap::ObjMap(const string& Name, Obj* pObj)
{
    if( PutObj(Name, pObj) )
    {
        cout<<"PutObj '"<<Name<<"' fail, pObj:"<<pObj<<endl;
    }
}

ObjMap::~ObjMap()
{
}

Obj *ObjMap::GetObj(const string& Name)
{
    map<string, Obj*>& ref = GetObjPools();
    map<string, Obj*>::iterator iter = ref.find(Name);
    if( iter != ref.end() )
    {
        return iter->second;
    }
    return NULL;
}
int ObjMap::PutObj(const string& Name, Obj* pObj)
{
    map<string, Obj*>& ref = GetObjPools();

    if( ref.insert( make_pair(Name, pObj) ).second) 
        return 0;
    return -1;
}

map<string, Obj*>& ObjMap::GetObjPools()
{
    static map<string, Obj*> s_ObjPools;
    return s_ObjPools;
}


